# -*- coding: utf-8 -*-
"""
Created on Tue Oct  4 08:59:06 2016

@author: zhiqiang

目的主要是加载处理清洗数据
"""
path = r'D:\学习\数据分析数据文件夹\精准资助\\'
test = 'test'
train = 'train'
from os import  listdir
train_files_name = listdir(path+train)
#首先加载图书馆的数据，简单处理后给出总的统计数据和分年的统计数据
files_name = path+train+'\\'+train_files_name[0]
borows = {}
borows_2013_2014 = {}
borows_2014_2015 = {}
from time import strptime
time1 = strptime("2013/09/01",'%Y/%m/%d')
time2 = strptime('2014/09/01','%Y/%m/%d')
time3 = strptime('2015/09/30','%Y/%m/%d')
with open(files_name,'rb') as fs:
    data = fs.readlines()
    for da in data:
        da = da.decode('utf-8')
        da = da.replace('\n','')
        da = da.replace('"','')
        das = da.split(',')
        borrow_time = strptime(das[1],'%Y/%m/%d')
        if borrow_time >= time1 and borrow_time<time2:
            if das[0] not in borows_2013_2014:
                borows_2013_2014.setdefault(das[0],1)
            else:
                borows_2013_2014[das[0]] = borows_2013_2014[das[0]]+1
        if borrow_time >= time2 and borrow_time<=time3:
            if das[0] not in borows_2014_2015:
                borows_2014_2015.setdefault(das[0],1)
            else:
                borows_2014_2015[das[0]] = borows_2014_2015[das[0]]+1
        if das[0] not in borows:
            borows.setdefault(das[0],1)
        else:
            borows[das[0]] = borows[das[0]]+1
#一卡通消费数据，处理结果存储在24维长度的
#['淋浴', '开水', '其他', '洗衣房', '文印中心', '教务处', '图书馆', '食堂', '校车', '', '超市', '校医院']
files_name = path+train+'\\'+train_files_name[1]
cards = {}
cards_2013_2014 = {}
cards_2014_2015 = {}
with open(files_name,'rb') as carddata:
    cdata = carddata.readlines()
    for cd in cdata:
        cd = cd.decode('utf-8')
        cd = cd.replace('\n','')
        cd = cd.replace('"','')
        cds = cd.split(',')
        if cds[0] not in cards:
            cards.setdefault(cds[0],{})
            cards[cds[0]][]=
        else:
            